/*
* 添加安全问题
* */

import 'dart:convert';

import 'package:center_beijing/api/authorization_api.dart';
import 'package:center_beijing/api/component_api.dart';
import 'package:center_beijing/api/product_api.dart';
import 'package:center_beijing/api/task_api.dart';
import 'package:center_beijing/common/QRScan.dart';
import 'package:center_beijing/common/logutil.dart';
import 'package:center_beijing/common/notification.dart';
import 'package:center_beijing/common/numLengthInputFormatter.dart';
import 'package:center_beijing/common/styles.dart';
import 'package:center_beijing/config/global_config.dart';
import 'package:center_beijing/config/routeConfig.dart';
import 'package:center_beijing/models/selectItem.dart';
import 'package:center_beijing/widgets/custom_input_widget.dart';
import 'package:center_beijing/widgets/custom_loading_widget.dart';
import 'package:center_beijing/widgets/custom_select_widget.dart';
import 'package:center_beijing/widgets/imageSelect_widget.dart';
import 'package:center_beijing/widgets/selectRow_widget.dart';
import 'package:center_beijing/widgets/select_widget.dart';
import 'package:center_beijing/widgets/textarea_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_pickers/time_picker/model/date_mode.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:get/get.dart' as Go;
import 'package:dio/dio.dart' as ImageForm;
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:images_picker/images_picker.dart';
import 'package:left_scroll_actions/cupertinoLeftScroll.dart';
import 'package:left_scroll_actions/global/actionListener.dart';
import 'dart:io';
import 'package:http_parser/http_parser.dart';
class AddSafetyProblem extends StatefulWidget {
  @override
  _AddSafetyProblemState createState() => _AddSafetyProblemState();
}

class _AddSafetyProblemState extends State<AddSafetyProblem> with SingleTickerProviderStateMixin {
  AnimationController _controller;
  CustomLoading loading = CustomLoading.withMessage('提交中...');
  final TextEditingController problemDescription =
  TextEditingController(); //问题描述
  final TextEditingController rectificationRequirements =
  TextEditingController(); //整改要求
  final TextEditingController deductPoints = TextEditingController(); //扣分
  final TextEditingController money = TextEditingController(); //罚金
  final TextEditingController stopDay = TextEditingController(); //停工
  final TextEditingController reason = TextEditingController(); //原因分析
  final TextEditingController projectName = TextEditingController(); //项目名称
  final TextEditingController comeFrom = TextEditingController(); //问题来源
  var rectification = ''; //整改期限
  var rectificationPerson = []; //整改人
  var ordinance; //条例
  var personPunish = []; //个人处罚
  String _newValue = '一般';
  List selectList = [];
  List<SelectItems> punishList = [];
  SelectItems selectPunish = SelectItems();

  List<SelectItems> teamList = [];
  SelectItems selectTeam = SelectItems(); //选择班组
  List<SelectItems> workAreaList = [];
  SelectItems selectWorkArea = SelectItems(); //选择工区
  Map department = Map(); //复检部门

  bool listHide = false;

  List<Media> photos = [];
  ImageForm.FormData formData;
  List passPhoto = [];

  @override
  void initState() {
    _controller = AnimationController(vsync: this);
    super.initState();
    this.getAllWorkArea();
    this.getAllPunishType();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

/*
  * 获取工区
  * */
  getAllWorkArea() async {
    var result = await getWorkArea({
      'projectSectionId': GlobalConfig.selectFactory.tag,
    });
    if (result != null) {
      List<SelectItems> tem = [];
      result.forEach((key, value) {
        tem.add(SelectItems(label: value, value: key));
      });
      this.setState(() {
        workAreaList = tem;
      });
    }
    LogUtil.d(result);
  }

  /*
  * 获取班组
  * */
  getAllTeam() async {
    var result = await getTeam({
      'workAreaId': selectWorkArea.value,
    });
    if (result != null) {
      List<SelectItems> tem = [];
      result.forEach((key, value) {
        tem.add(SelectItems(label: value, value: key));
      });
      this.setState(() {
        teamList = tem;
      });
    }
    LogUtil.d(result);
  }

  /*
  * 获取处罚类型
  * */
  getAllPunishType() async {
    var result = await getPunishType({'codeType': 'BIM-TW-163'});
    if (result != null) {
      List<SelectItems> tem = [];
      result.forEach((item) {
        tem.add(SelectItems(label: item['name'], value: item['code']));
      });
      this.setState(() {
        punishList = tem;
      });
    }
    LogUtil.d(result);
  }

  /*
  * 获取构件详情
  * */
  getCompDetail(compId) async {
    bool have = false;
    for (var i = 0; i < selectList.length; i++) {
      if (selectList[i]['id'] == compId) {
        have = true;
        break;
      }
    }
    if (!have) {
      var result = await getComponentDetail(compId);
      if (result != null) {
        if(result['state'].toString() == '3'){
          Fluttertoast.showToast(msg: '构件已经报废');
        } else {
          this.setState(() {
            selectList.add(result);
          });
        }
      }
    }
  }

  submit() async {
    var pass = {
      'tenantId': GlobalConfig.tenantId,
      'startDeptId': department['id'],
      'executorList': json.encode(rectificationPerson.map((item) {
        return {
          'userId': item['userId'],
          'name': item['name'],
          'mobile': item['mobile']
        };
      }).toList()),
      'param': json.encode({
        'qsCheckRecord': {
          'level': _newValue == '一般' ? 1 : (_newValue == '次要' ? 2 : 3),
          'summary': problemDescription.text,
          'rectifyAsk': rectificationRequirements.text,
          'issueType2': 1,
          'deadlineDate': rectification,
          'workAreaId': selectWorkArea.value,
          'workerTeamId': selectTeam.value,
          'projectSectionId': GlobalConfig.selectFactory.tag,
          'scoreNormId': ordinance['id'].replaceAll('task_', ''),
          'punishmentType': selectPunish.value,
          'teamScore': this.deductPoints.text,
          'teamAmount': money.text,
          'suspensionDays': stopDay.text,
          'issueAnalysis': reason.text,
          'recordSourceType': 'app',
          'recordName':projectName.text,
          'issueKind':comeFrom.text
        },
        'qsIssuePersonList': personPunish.map((e) {
          return {
            'punishmentType': e['punishTypeNum'],
            'workerScore': e['point'],
            'workerId': e['id']
          };
        }).toList(),
        'elementIds': selectList.map((e) {
          return e['id'];
        }).toList(),
        'photoIds': passPhoto.map((e) {
          return e['attachmentId'];
        }).toList()
      })
    };
    var result = await submitTask(pass);
    loading.dismiss();
    if (result['text'] != null && result['text'] == '') {
      Fluttertoast.showToast(msg: '提交成功');
      bus.emit('refreshHome');
      Go.Get.back();
    }
    // LogUtil.d(result);
  }

  /*
  * 判断必填
  * */
  justifyInfo() {
    if (ordinance == null) {
      Fluttertoast.showToast(msg: '请选择条例');
      return false;
    }else if (problemDescription.text == '') {
      Fluttertoast.showToast(msg: '请输入问题描述');
      return false;
    } else if (rectificationRequirements.text == '') {
      Fluttertoast.showToast(msg: '请输入整改要求');
      return false;
    } else if (rectification == '') {
      Fluttertoast.showToast(msg: '请选择整改期限');
      return false;
    }else if (rectificationPerson.length == 0) {
      Fluttertoast.showToast(msg: '请选择整改人');
      return false;
    }  else if (selectWorkArea.value == null) {
      Fluttertoast.showToast(msg: '请选择工区');
      return false;
    } else if (selectTeam.value == null) {
      Fluttertoast.showToast(msg: '请选择班组');
      return false;
    }  else if (selectPunish.value == null) {
      Fluttertoast.showToast(msg: '请选择处罚');
      return false;
    } else if (this.deductPoints.text == '') {
      Fluttertoast.showToast(msg: '请输入扣分');
      return false;
    } else if (this.reason.text == '') {
      Fluttertoast.showToast(msg: '请输入原因分析');
      return false;
    }else if (department['id'] == null) {
      Fluttertoast.showToast(msg: '请选择复检部门');
      return false;
    }else if (projectName.text.isEmpty) {
      Fluttertoast.showToast(msg: '请输入整改项目名称');
      return false;
    }else if (comeFrom.text.isEmpty) {
      Fluttertoast.showToast(msg: '请输入问题来源');
      return false;
    }else{
      return true;
    }
  }

  Future addImage() async {

    loading.show(delay: 30);
    if (this.photos.length > 0) {
      var temPhotos = [];
      temPhotos.addAll(this.photos);
      formData = new ImageForm.FormData.fromMap({
        "tenantId": GlobalConfig.tenantId,
      });
      for (int i = 0; i < temPhotos.length; i++) {
        Media asset = temPhotos[i];
        File file = File(asset.path);
        formData.files.add(MapEntry("files",
            await ImageForm.MultipartFile.fromFile(file.path.toString(),contentType: MediaType('image',file.path.toString().split('.').last))));
      }
      var result = await uploadImage(formData, GlobalConfig.tenantId);
      if (result != null && result.length > 0) {
        this.passPhoto = result;
        this.submit();
      }
    } else {
      this.submit();
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('安全问题填报'),
        ),
        body: GestureDetector(
          onTap: () {
            FocusScope.of(context).requestFocus(FocusNode());
          },
          child: Container(
            color: Styles.MainBackgroundColor,
            padding: EdgeInsets.fromLTRB(
                0, 0, 0, MediaQuery.of(context).padding.bottom + 70),
            child: SingleChildScrollView(
              child: Column(
                children: [
                  Container(
                    alignment: Alignment.centerLeft,
                    padding: EdgeInsets.fromLTRB(Styles.spacing16,
                        Styles.spacing12, Styles.spacing8, Styles.spacing8),
                    child: RichText(
                        text: TextSpan(children: [
                          TextSpan(
                            text: '*',
                            style: TextStyle(
                                fontSize: Styles.NormalFont, color: Styles.RedColor),
                          ),
                          TextSpan(
                            text: "安全标准/条例",
                            style: TextStyle(
                                fontSize: Styles.NormalFont,
                                color: Styles.DetailColor),
                          ),

                        ])),
                  ),
                  GestureDetector(
                    behavior: HitTestBehavior.translucent,
                    onTap: () async {
                      var select =
                      await Go.Get.toNamed(RouteConfig.selectSafetyOrdinance);
                      if (select != null) {
                        this.setState(() {
                          ordinance = select;
                        });
                      }
                    },
                    child: Container(
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                          border:
                          Border.all(color: Styles.BlueColor, width: 1)),
                      padding: EdgeInsets.fromLTRB(Styles.spacing8,
                          Styles.spacing12, Styles.spacing8, Styles.spacing12),
                      margin: EdgeInsets.fromLTRB(
                          Styles.spacing16, 0, Styles.spacing16, 0),
                      child: Text(
                        this.ordinance != null
                            ? this.ordinance['name']
                            : '选择标准/条例',
                        style: TextStyle(
                            color: Styles.BlueColor,
                            fontSize: Styles.NormalFont),
                      ),
                    ),
                  ),
                  Container(
                    color: Colors.white,
                    child: Column(
                      children: [
                        Padding(
                          padding: EdgeInsets.fromLTRB(
                              Styles.spacing16, Styles.spacing8, 0, 0),
                          child: Row(
                            children: <Widget>[
                              Text(
                                '问题等级',
                                style: TextStyle(
                                    color: Styles.DetailColor,
                                    fontSize: Styles.MiddleFont17),
                              ),
                            ],
                          ),
                        ),
                        Container(
                          padding: EdgeInsets.fromLTRB(
                              Styles.spacing16, 0, Styles.spacing8, 0),
                          color: Colors.white,
                          child: Row(
                            children: [
                              Expanded(
                                  child: Row(
                                    mainAxisAlignment: MainAxisAlignment.center,
                                    children: [
                                      Text(
                                        '一般',
                                        style: TextStyle(
                                            color: Styles.DetailColor,
                                            fontSize: Styles.NormalFont),
                                      ),
                                      Radio<String>(
                                          value: "一般",
                                          activeColor: Styles.BlueColor,
                                          groupValue: _newValue,
                                          onChanged: (value) {
                                            setState(() {
                                              _newValue = value;
                                            });
                                          }),
                                    ],
                                  )),
                              Expanded(
                                  child: Row(
                                    mainAxisAlignment: MainAxisAlignment.center,
                                    children: [
                                      Text(
                                        '次要',
                                        style: TextStyle(
                                            color: Styles.DetailColor,
                                            fontSize: Styles.NormalFont),
                                      ),
                                      Radio<String>(
                                          value: "次要",
                                          activeColor: Styles.BlueColor,
                                          groupValue: _newValue,
                                          onChanged: (value) {
                                            setState(() {
                                              _newValue = value;
                                            });
                                          }),
                                    ],
                                  )),
                              Expanded(
                                  child: Row(
                                    mainAxisAlignment: MainAxisAlignment.center,
                                    children: [
                                      Text(
                                        '重要',
                                        style: TextStyle(
                                            color: Styles.DetailColor,
                                            fontSize: Styles.NormalFont),
                                      ),
                                      Radio<String>(
                                          value: "重要",
                                          activeColor: Styles.BlueColor,
                                          groupValue: _newValue,
                                          onChanged: (value) {
                                            setState(() {
                                              _newValue = value;
                                            });
                                          }),
                                    ],
                                  ))
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                  Container(
                    color: Colors.white,
                    margin: EdgeInsets.fromLTRB(0, Styles.spacing8, 0, 0),
                    padding: EdgeInsets.fromLTRB(
                        Styles.spacing8, 0, Styles.spacing8, 0),
                    child: TextAreaWidget(
                      textController: problemDescription,
                      labelText: '问题描述',
                      defaultValue: '',
                      placeholder: '请输入',
                      disabled: false,
                      required: true,
                      rows: 4,
                      onChange: (value) => this.setState(() {}),
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.fromLTRB(0, Styles.spacing8, 0, 0),
                    color: Colors.white,
                    child: Column(
                      children: [
                        Padding(
                          padding: EdgeInsets.fromLTRB(
                              Styles.spacing16, Styles.spacing8, 0, 0),
                          child: Row(
                            children: <Widget>[
                              Text(
                                '问题照片(${this.photos.length}/6)',
                                style: TextStyle(
                                    color: Styles.DetailColor,
                                    fontSize: Styles.MiddleFont17),
                              ),
                            ],
                          ),
                        ),
                        ImageSelectWidget(
                          onchange: (value) {
                            this.setState(() {
                              photos = value;
                            });
                          },
                        ),
                      ],
                    ),
                  ),
                  Container(
                    color: Colors.white,
                    margin: EdgeInsets.fromLTRB(0, Styles.spacing8, 0, 0),
                    padding: EdgeInsets.fromLTRB(
                        Styles.spacing8, 0, Styles.spacing8, 0),
                    child: TextAreaWidget(
                      textController: rectificationRequirements,
                      labelText: '整改要求',
                      defaultValue: '',
                      placeholder: '请输入',
                      disabled: false,
                      required: true,
                      rows: 4,
                      onChange: (value) => this.setState(() {}),
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.fromLTRB(0, Styles.spacing8, 0, 0),
                    color: Colors.white,
                    padding: EdgeInsets.fromLTRB(Styles.spacing8, 0, 0, 0),
                    child: SelectRow(
                        selectType: DateMode.YMD,
                        require: true,
                        title: '整改期限',
                        rightText: rectification,
                        selectCallback: (value) {
                          this.setState(() {
                            rectification = value;
                          });
                        }),
                  ),
                  Container(
                    margin: EdgeInsets.fromLTRB(0, Styles.spacing8, 0, 0),
                    color: Colors.white,
                    child: SelectWidget(
                      require: true,
                      title: '整改人员',
                      rightText: this
                          .rectificationPerson
                          .map((item) {
                        return item['name'];
                      })
                          .toList()
                          .join(','),
                      selectCallback: () async {
                        var select =
                        await Go.Get.toNamed(RouteConfig.selectPerson,arguments: '1');
                        if (select != null) {
                          this.setState(() {
                            rectificationPerson = select;
                          });
                        }
                      },
                    ),
                  ),
                  Container(
                    alignment: Alignment.centerLeft,
                    padding: EdgeInsets.fromLTRB(Styles.spacing16,
                        Styles.spacing12, Styles.spacing8, Styles.spacing8),
                    child: Text(
                      '关联构件',
                      style: TextStyle(
                          color: Styles.TitleColor,
                          fontSize: Styles.NormalFont),
                    ),
                  ),
                  Container(
                    color: Colors.white,
                    padding: EdgeInsets.fromLTRB(Styles.spacing16,
                        Styles.spacing8, Styles.spacing16, Styles.spacing8),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Row(
                          children: [
                            RichText(
                                text: TextSpan(children: [
                                  TextSpan(
                                      text: '已选构件（',
                                      style: TextStyle(
                                          color: Styles.DetailColor,
                                          fontSize: Styles.NormalFont)),
                                  TextSpan(
                                      text: selectList.length.toString(),
                                      style: TextStyle(
                                          color: Styles.BlueColor,
                                          fontSize: Styles.NormalFont)),
                                  TextSpan(
                                      text: '）',
                                      style: TextStyle(
                                          color: Styles.DetailColor,
                                          fontSize: Styles.NormalFont)),
                                ])),
                            GestureDetector(
                              onTap: () {
                                print('点击');
                                this.setState(() {
                                  listHide = !listHide;
                                });
                              },
                              child: Container(
                                padding: EdgeInsets.fromLTRB(
                                    Styles.spacing8, 0, 0, 0),
                                child: Text(
                                  '点击查看',
                                  style: TextStyle(
                                      color: Styles.BlueColor,
                                      fontSize: Styles.NormalFont),
                                ),
                              ),
                            )
                          ],
                        ),
                        GestureDetector(
                          onTap: () async {
                            var result = await QrScan.scan(context);
                            if (result != null) {
                              if (result['type'] == 1) {
                                this.getCompDetail(result['code']);
                              } else {
                                showDialog(
                                    barrierDismissible: false,
                                    context: context,
                                    builder: (BuildContext context) {
                                      return AlertDialog(
                                        title: Text('注意'),
                                        content: Text('请扫描构件二维码！'),
                                        actions: <Widget>[
                                          new Container(
                                            child: FlatButton(
                                              child: new Text(
                                                "确定",
                                                style: TextStyle(color: Colors.red),
                                              ),
                                              onPressed: () {
                                                Navigator.pop(context);
                                              },
                                            ),
                                          ),

                                        ],
                                      );
                                    });
                              }
                            }
                          },
                          child: Container(
                            padding: EdgeInsets.fromLTRB(
                                Styles.spacing8,
                                Styles.spacing8,
                                Styles.spacing8,
                                Styles.spacing8),
                            decoration: BoxDecoration(
                                gradient: LinearGradient(
                                  colors: [
                                    Colors.blue,
                                    Styles.BlueColor,
                                  ],
                                ),
                                borderRadius:
                                BorderRadius.all(Radius.circular(4.0.r))),
                            child: RichText(
                              text: TextSpan(children: [
                                WidgetSpan(
                                  alignment: PlaceholderAlignment.middle,
                                  child: Image.asset(
                                    'assets/images/scan.png',
                                    width: 12.w,
                                    height: 12.h,
                                    color: Colors.white,
                                  ),
                                ),
                                TextSpan(
                                    text: '  ',
                                    style: TextStyle(
                                        color: Styles.ShareWhite,
                                        fontSize: Styles.NormalFont)),
                                TextSpan(
                                    text: '扫码添加构件',
                                    style: TextStyle(
                                        color: Styles.ShareWhite,
                                        fontSize: Styles.NormalFont)),
                              ]),
                            ),
                          ),
                        )
                      ],
                    ),
                  ),
                  !listHide
                      ? Column(
                    children: this.selectList.map((item) {
                      return CupertinoLeftScroll(
                        // important, each Row must have different key.
                        // DO NOT use '$index' as Key! Use id or title.
                        key: Key(item.toString()),
                        // left scroll widget will auto close while the other widget is opened and has same closeTag.
                        // 当另一个有相同closeTag的组件打开时，其他有着相同closeTag的组件会自动关闭.
                        closeTag: LeftScrollCloseTag(item.toString()),
                        buttonWidth: 80,
                        child: Container(
                          color: Colors.white,
                          padding: EdgeInsets.fromLTRB(
                              Styles.spacing8,
                              Styles.spacing8,
                              Styles.spacing8,
                              Styles.spacing8),
                          margin: EdgeInsets.only(top: Styles.spacing8),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Row(
                                children: [
                                  Container(
                                    margin: EdgeInsets.only(
                                        right: Styles.spacing8),
                                    height: 20.h,
                                    width: 4.w,
                                    color: Styles.BlueColor,
                                  ),
                                  Text(
                                    (item['compKind'] != null &&
                                        item['compKind']
                                        ['compKindName'] !=
                                            null)
                                        ? item['compKind']['compKindName']
                                        : '--',
                                    style: TextStyle(
                                        color: Styles.DetailColor,
                                        fontSize: Styles.Middle16Font),
                                  ),
                                ],
                              ),
                              Container(
                                margin: EdgeInsets.fromLTRB(
                                    Styles.spacing8,
                                    0,
                                    Styles.spacing8,
                                    0),
                                child: Column(
                                  crossAxisAlignment:
                                  CrossAxisAlignment.start,
                                  children: [
                                    Text(
                                      item['code'] != null
                                          ? item['code']
                                          : '--',
                                      style: TextStyle(
                                          color: Styles.DetailColor,
                                          fontSize: Styles.Middle16Font),
                                    ),
                                    Text(
                                      (item['orderInfo'] != null &&
                                          item['orderInfo']
                                          ['orderName'] !=
                                              null)
                                          ? item['orderInfo']['orderName']
                                          : '--',
                                      style: TextStyle(
                                          color: Styles.LeftTitleColor,
                                          fontSize: Styles.NormalFont),
                                    ),
                                    Text(
                                      item['levelPath'] != null
                                          ? (item['levelPath']
                                          .split('&_&_&'))
                                          .join('-')
                                          : '--',
                                      style: TextStyle(
                                          color: Styles.LeftTitleColor,
                                          fontSize: Styles.NormalFont),
                                    ),
                                  ],
                                ),
                              )
                            ],
                          ),
                        ),
                        buttons: <Widget>[
                          GestureDetector(
                            onTap: () {
                              this.setState(() {
                                selectList.remove(item);
                              });
                              print('删除');
                            },
                            child: Container(
                              margin: EdgeInsets.fromLTRB(
                                  0, 0, Styles.spacing16, 0),
                              decoration: BoxDecoration(
                                color: Styles.RedColor,
                                borderRadius: BorderRadius.all(
                                    Radius.circular(14.0.r)),
                              ),
                              alignment: Alignment.center,
                              child: Column(
                                mainAxisAlignment:
                                MainAxisAlignment.center,
                                children: [
                                  Image(
                                    image: AssetImage(
                                        'assets/images/delete.png'),
                                    width: 16.w,
                                    height: 16.w,
                                    fit: BoxFit.contain,
                                  ),
                                  Text(
                                    '删除',
                                    style: TextStyle(
                                        color: Colors.white,
                                        fontSize: Styles.NormalFont),
                                  )
                                ],
                              ),
                            ),
                          ),
                        ],
                        onTap: () {
                          print('tap row');
                        },
                      );
                    }).toList(),
                  )
                      : Container(),
                  Container(
                    alignment: Alignment.centerLeft,
                    padding: EdgeInsets.fromLTRB(Styles.spacing16,
                        Styles.spacing12, Styles.spacing8, Styles.spacing8),
                    child: Text(
                      '责任关联',
                      style: TextStyle(
                          color: Styles.TitleColor,
                          fontSize: Styles.NormalFont),
                    ),
                  ),
                  Container(
                    color: Colors.white,
                    margin: EdgeInsets.fromLTRB(0, Styles.spacing8, 0, 0),
                    child: CustomSelectWidget(
                      require: true,
                      rightText: selectWorkArea.label != null
                          ? selectWorkArea.label
                          : '请选择',
                      items: workAreaList,
                      selectCallback: (value) => this.setState(() {
                        selectWorkArea = value;
                        teamList = [];
                        selectTeam = SelectItems();
                        this.getAllTeam();
                      }),
                      title: '选择工区',
                    ),
                  ),
                  selectWorkArea.value!=null?Container(
                    color: Colors.white,
                    margin: EdgeInsets.fromLTRB(0, Styles.spacing8, 0, 0),
                    child: CustomSelectWidget(
                      require: true,
                      rightText:
                      selectTeam.label != null ? selectTeam.label : '请选择',
                      items: teamList,
                      selectCallback: (value) => this.setState(() {
                        selectTeam = value;
                      }),
                      title: '选择班组',
                    ),
                  ):Container(),
                  Container(
                    color: Colors.white,
                    margin: EdgeInsets.fromLTRB(0, Styles.spacing8, 0, 0),
                    child: CustomSelectWidget(
                      require: true,
                      rightText: selectPunish.label != null
                          ? selectPunish.label
                          : '请选择',
                      items: punishList,
                      selectCallback: (value) => this.setState(() {
                        selectPunish = value;
                      }),
                      title: '选择处罚',
                    ),
                  ),
                  this.selectPunish.value != null
                      ? Container(
                    child: Row(
                      children: [
                        Expanded(
                            child: Container(
                              margin: EdgeInsets.fromLTRB(
                                  0, Styles.spacing8, 0, 0),
                              padding: EdgeInsets.fromLTRB(
                                  Styles.spacing8, 0, Styles.spacing8, 0),
                              child: CustomInput(
                                inputformat: [
                                  LengthLimitingTextInputFormatter(3),
                                  WhitelistingTextInputFormatter(
                                      RegExp("[0-9]"))
                                ],
                                title: '扣分',
                                placeHold: '请输入',
                                textInput: this.deductPoints,
                                clearAll: false,
                                require: true,
                              ),
                            )),
                        this.selectPunish.value != '5'
                            ? (this.selectPunish.value == '2'
                            ? Expanded(
                            child: Container(
                              color: Colors.white,
                              margin: EdgeInsets.fromLTRB(
                                  0, Styles.spacing8, 0, 0),
                              padding: EdgeInsets.fromLTRB(
                                  Styles.spacing8,
                                  0,
                                  Styles.spacing8,
                                  0),
                              child: CustomInput(
                                keyboardType: TextInputType.number,
                                inputformat: [
                                  LengthLimitingTextInputFormatter(
                                      20),
                                  WhitelistingTextInputFormatter(
                                      RegExp("[0-9]"))
                                ],
                                title: '天数',
                                placeHold: '停工天数',
                                textInput: this.stopDay,
                                clearAll: false,
                                require: false,
                              ),
                            ))
                            : Container())
                            : Expanded(
                            child: Container(
                              color: Colors.white,
                              margin: EdgeInsets.fromLTRB(
                                  0, Styles.spacing8, 0, 0),
                              padding: EdgeInsets.fromLTRB(
                                  Styles.spacing8,
                                  0,
                                  Styles.spacing8,
                                  0),
                              child: CustomInput(
                                keyboardType: TextInputType.number,
                                inputformat: [
                                  LengthLimitingTextInputFormatter(20),
                                  NumLengthInputFormatter(digit: 2)
                                ],
                                title: '罚金',
                                placeHold: '请输入',
                                textInput: this.money,
                                clearAll: false,
                                require: false,
                              ),
                            )),
                      ],
                    ),
                  )
                      : Container(),
                  GestureDetector(
                    behavior: HitTestBehavior.translucent,
                    onTap: () async {
                      if (selectTeam.value != null) {
                        var select = await Go.Get.toNamed(
                            RouteConfig.selectPunishPerson,
                            arguments: selectTeam);
                        if (select != null) {
                          this.setState(() {
                            personPunish = select;
                          });
                        }
                      } else {
                        Fluttertoast.showToast(msg: '请先选择班组');
                      }
                    },
                    child: Container(
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                          border: Border.all(color: Styles.BlueColor, width: 1),
                          color: Colors.white),
                      padding: EdgeInsets.fromLTRB(Styles.spacing8,
                          Styles.spacing12, Styles.spacing8, Styles.spacing12),
                      margin: EdgeInsets.fromLTRB(Styles.spacing16,
                          Styles.spacing16, Styles.spacing16, 0),
                      child: Text(
                        '添加个人处罚',
                        style: TextStyle(
                            color: Styles.BlueColor,
                            fontSize: Styles.NormalFont),
                      ),
                    ),
                  ),
                  Container(
                    child: Column(
                      children: this.personPunish.map((item) {
                        return Container(
                          color: Colors.white,
                          padding: EdgeInsets.fromLTRB(
                              Styles.spacing16,
                              Styles.spacing4,
                              Styles.spacing16,
                              Styles.spacing4),
                          child: Row(
                            children: [
                              Text(
                                  "${item['name']}:${item['punishType']} 扣分${item['point']}")
                            ],
                          ),
                        );
                      }).toList(),
                    ),
                  ),
                  Container(
                    color: Colors.white,
                    margin: EdgeInsets.fromLTRB(0, Styles.spacing8, 0, 0),
                    padding: EdgeInsets.fromLTRB(
                        Styles.spacing8, 0, Styles.spacing8, 0),
                    child: TextAreaWidget(
                      textController: reason,
                      labelText: '原因分析',
                      defaultValue: '',
                      placeholder: '请输入',
                      disabled: false,
                      required: true,
                      rows: 4,
                      onChange: (value) => this.setState(() {}),
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.fromLTRB(0, Styles.spacing8, 0, 0),
                    color: Colors.white,
                    child: SelectWidget(
                      title: '复检部门',
                      require: true,
                      rightText:
                      department['name'] != null ? department['name'] : '',
                      selectCallback: () async {
                        var select =
                        await Go.Get.toNamed(RouteConfig.selectDepartment,arguments: 1);
                        if (select != null) {
                          this.setState(() {
                            department = select;
                          });
                        }
                      },
                    ),
                  ),
                  Container(
                    color: Colors.white,
                    margin: EdgeInsets.fromLTRB(0, Styles.spacing8, 0, 0),
                    padding: EdgeInsets.fromLTRB(
                        Styles.spacing8, 0, Styles.spacing8, 0),
                    child: CustomInput(
                      textAlign: TextAlign.right,
                      inputformat: [
                        LengthLimitingTextInputFormatter(20),
                      ],
                      title: '项目名称',
                      placeHold: '请输入',
                      textInput: this.projectName,
                      clearAll: false,
                      require: true,
                    ),

                  ),
                  Container(
                    color: Colors.white,
                    margin: EdgeInsets.fromLTRB(0, Styles.spacing8, 0, 0),
                    padding: EdgeInsets.fromLTRB(
                        Styles.spacing8, 0, Styles.spacing8, 0),
                    child: CustomInput(
                      textAlign: TextAlign.right,
                      inputformat: [
                        LengthLimitingTextInputFormatter(20),
                      ],
                      title: '问题来源',
                      placeHold: '请输入',
                      textInput: this.comeFrom,
                      clearAll: false,
                      require: true,
                    ),

                  )
                ],
              ),
            ),
          ),
        ),
        floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
        floatingActionButton: Container(
          padding: EdgeInsets.fromLTRB(
              Styles.spacing8, Styles.spacing8, Styles.spacing8, 10),
          child: Container(
            decoration: new BoxDecoration(
              //背景
              color: Styles.BlueColor,
              //设置四周圆角 角度
              borderRadius: BorderRadius.all(Radius.circular(12.0)),
            ),
            child: FlatButton(
              disabledColor: Styles.SelectColor,
              onPressed: () {
                FocusScope.of(context).requestFocus(new FocusNode());
                if (this.justifyInfo()) {
                  showDialog(
                      barrierDismissible: false,
                      context: this.context,
                      builder: (BuildContext context) {
                        return AlertDialog(
                          title: Text('注意'),
                          content: Text('确认提交吗？'),
                          actions: <Widget>[
                            new Container(
                              child: FlatButton(
                                child: new Text(
                                  "取消",
                                  style: TextStyle(color: Colors.black),
                                ),
                                onPressed: () {
                                  Navigator.pop(context);
                                },
                              ),
                            ),
                            new Container(
                              child: FlatButton(
                                child: new Text(
                                  "确定",
                                  style: TextStyle(color: Colors.red),
                                ),
                                onPressed: () {
                                  Navigator.pop(context);
                                  this.addImage();
                                },
                              ),
                            ),
                          ],
                        );
                      });
                }

              },
              child: Container(
                height: Styles.MainButtonHeight,
                alignment: Alignment.center,
                child: Text(
                  '确认提交',
                  style: TextStyle(
                      fontSize: Styles.MainButtonTextFont, color: Colors.white),
                ),
              ),
            ),
          ),
        ));
  }
}
